package com.qufadai.reader.web.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.qufadai.reader.entity.TickerEntity;
import com.qufadai.reader.entity.User;
import com.qufadai.reader.service.TickerService;
import com.qufadai.reader.service.UserService;
import com.qufadai.reader.util.Constant;

@Controller
public class IndexController {

	@Autowired
	private UserService userService;
	@Autowired
	private TickerService tickerService;

	@RequestMapping("/index")
	public String index() {
		User user = this.userService.findUserById(123);
		System.out.println("Controller->index");
		System.out.println(user);
		return "index";
	}

	@RequestMapping(value = "/register", method = RequestMethod.GET)
	public String register() {

		return "register";
	}

	@RequestMapping(value = "/ticker", method = RequestMethod.GET)
	public String ticker(Map<String, Object> model) {
		List<TickerEntity> tickerList = tickerService.findBySourceAndCoinType(
				Constant.SOURCE_BTER, Constant.COIN_TYPE_DTC);
		model.put("dtcTickerList", tickerList);
		tickerList = tickerService.findBySourceAndCoinType(
				Constant.SOURCE_BTER, Constant.COIN_TYPE_XPM);
		model.put("xpmTickerList", tickerList);
		tickerList = tickerService.findBySourceAndCoinType(
				Constant.SOURCE_BTC_E, Constant.COIN_TYPE_BTC);
		model.put("btcTickerList", tickerList);
		tickerList = tickerService.findBySourceAndCoinType(
				Constant.SOURCE_BTC_E, Constant.COIN_TYPE_LTC);
		model.put("ltcTickerList", tickerList);
		tickerList = tickerService.findBySourceAndCoinType(
				Constant.SOURCE_BTC_E, Constant.COIN_TYPE_NMC);
		model.put("nmcTickerList", tickerList);

		return "ticker";
	}
}
